{% load jrc_shared %}

{% for week in month %}

    {% if week.monday != 0 %}
        {% for tr in week.get_forex_tracks_for_monday %}
            <tr class="row1">
                {% include "tracking/_forex_tr.html" with tr=tr %}
            </tr>
        {% empty %}
            <tr class="row1">
                
                <td style="color: darkgray;" nowrap>{{ week.get_date_for_monday|date:"d" }}, Mon</td>
                <td colspan="15" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.tuesday != 0 %}
        {% for tr in week.get_forex_tracks_for_tuesday %}
            <tr class="row2">
                {% include "tracking/_forex_tr.html" with tr=tr %}
            </tr>
        {% empty %}
            <tr class="row2">
                
                <td style="color: darkgray;">{{ week.get_date_for_tuesday|date:"d" }}, Tue</td>
                <td colspan="15" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}
    
    {% if week.wednesday != 0 %}
        {% for tr in week.get_forex_tracks_for_wednesday %}
            <tr class="row1">
                {% include "tracking/_forex_tr.html" with tr=tr %}
            </tr>
        {% empty %}
            <tr class="row1">
                
                <td style="color: darkgray;" nowrap>{{ week.get_date_for_wednesday|date:"d" }}, Wed</td>
                <td colspan="15" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.thursday != 0 %}
        {% for tr in week.get_forex_tracks_for_thursday %}
            <tr class="row2">
                {% include "tracking/_forex_tr.html" with tr=tr %}
            </tr>
        {% empty %}
            <tr class="row2">
                
                <td style="color: darkgray;">{{ week.get_date_for_thursday|date:"d" }}, Thu</td>
                <td colspan="15" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.friday != 0 %}
        {% for tr in week.get_forex_tracks_for_friday %}
            <tr class="row1">
                {% include "tracking/_forex_tr.html" with tr=tr %}
            </tr>
        {% empty %}
            <tr class="row1">
                
                <td style="color: darkgray;">{{ week.get_date_for_friday|date:"d" }}, Fri</td>
                <td colspan="15" style="color: darkgray;">No tracks</td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    {% if week.saturday != 0 %}
        {% for tr in week.get_forex_tracks_for_saturday %}
            <tr class="row2">
                {% include "tracking/_forex_tr.html" with tr=tr %}
            </tr>
        {% empty %}
            <tr class="row2">
                <td style="color: red;">{{ week.get_date_for_saturday|date:"d" }}, Sat</td>
                <td colspan="15"></td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}
    
    {% if week.sunday != 0 %}
        {% for tr in week.get_forex_tracks_for_sunday %}
            <tr class="row1">
                {% include "tracking/_forex_tr.html" with tr=tr %}
            </tr>
        {% empty %}
            <tr class="row1">
                <td style="color: red;">{{ week.get_date_for_sunday|date:"d" }}, Sun</td>
                <td colspan="15"></td>
            </tr>
        {% endfor %}
    {% else %}
        {# Previous or next month #}
    {% endif %}

    <tr>
        <td colspan="18" style="border-top: solid 1px black;">&nbsp;</td>
    </tr>

{% endfor %}
    
    <tr style="font-weight: bold;">
        <td>Totals</td>
        <td>&nbsp;</td>
        <td>{{ month_stats.fees_total }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>{{ month_stats.pl_pips_total|jrc_intformat }}</td>
        <td>{{ month_stats.pl_pips_f_total|jrc_intformat }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>{{ month_stats.pl_pips_div_eur_total|jrc_intformat }}</td>
        <td>{{ month_stats.pl_pips_f_div_eur_total|jrc_intformat }}</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        
    </tr>

<script type="text/javascript">

//    gMarketsTotalsMin = {{ month_stats.markets_totals_min }};
//    gMarketsTotalsMax = {{ month_stats.markets_totals_max }};
    gArMarketsNamesAndTotals = [
        ['Markets', ''],
        {% for m, v in month_stats.markets_totals.iteritems %}
            ["{{ m }}", {{ v }}],
        {% endfor %}
    ];

    {% for m, v in month_stats.markets_totals.iteritems %}
        gArMarketsNames[gArMarketsNames.length] = "{{ m }}";
        gArMarketsTotals[gArMarketsTotals.length] = {{ v }};
    {% endfor %}


    {# Put accumulated Fess here, P/L pips will be next for #}
    {% for f in month_stats.fees_accumulated %}
        gArProfitLossesAndFeesData[{{ forloop.counter0 }}] = ['{{ forloop.counter }}', -1, {{ f }}];
    {% endfor %}
    
    {# Add P/L pips to array #}
    {% for p in month_stats.pl_accumulated %}
        gArProfitLossesAndFeesData[{{ forloop.counter0 }}][1] = {{ p }};
    {% endfor %}

    {# P/L pips w/ and w/o fees (EUR) #}
    {% for p in month_stats.pl_pips_f_accumulated %}
        gArProfitLossesAndFeesEurData[{{ forloop.counter0 }}] = ['{{ forloop.counter }}', -1, {{ p }}];
    {% endfor %}

    {% for p in month_stats.pl_pips_accumulated %}
        gArProfitLossesAndFeesEurData[{{ forloop.counter0 }}][1] = {{ p }};
    {% endfor %}

//    {% for p in month_stats.pl_pips_f_div_eur %}
//        gArProfitLossesAndFeesEurData[{{ forloop.counter0 }}][1] = {{ p }};
//    {% endfor %}

//    {% for p in month_stats.pl_pips_accumulated %}
//        gArPips[{{ forloop.counter0 }}] = ["{{ forloop.counter }}", -1, {{ p }}];
//    {% endfor %}
//
//    {% for p in month_stats.pl_pips_f_accumulated %}
//        gArPips[{{ forloop.counter0 }}][1] = {{ p }};
//    {% endfor %}

    
</script>
